﻿// LSTM_WIN.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <iostream>
//#include "dataset.h"
//#include "Tensor.h"
#include "Matrix.h"
#include "Matrix_avx2.h"


template <typename Func>
double measureExecutionTime(Func func, int iterations)
{
    auto start = std::chrono::high_resolution_clock::now();
    for (int i = 0; i < iterations; ++i) {
        func();
    }
    auto end = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double> duration = end - start;
    return duration.count();
}


//int main() {
//    std::string basedir = "D:/CPP/captcha_lstm_cpp/dataset/verify_code_xuexin_all/train/";
//    CodeDataset dataset(basedir);
//
//    std::vector<ImgLable> batch;
//    for (size_t i = 0; i < 4; ++i) { // 假设批量大小为2
//        batch.push_back(dataset.get_sample(i));
//    }
//
//    auto [Tensor_imgs, Tensor_labs, seq_lengths] = collate_fn(batch);
//
//    std::cout << "Images size: " << Tensor_imgs.size() << std::endl;
//    std::cout << "Labels size: " << Tensor_labs.size() << std::endl;
//    std::cout << "Sequence Lengths: ";
//    for (auto& len : seq_lengths) {
//        std::cout << len << " ";
//    }
//    std::cout << std::endl;
//
//    return 0;
//}


/*
* /////////////////////////////////////////////////////////
* ///                test dataset loader
* /////////////////////////////////////////////////////////
int main() {
    std::string basedir = "D:/CPP/captcha_lstm_cpp/dataset/verify_code_xuexin_all/train/";
    CodeDataset dataset(basedir);

    std::vector<ImgLable> batch;
    for (size_t i = 0; i < 4; ++i) { // 假设批量大小为2
        batch.push_back(dataset.get_sample(i));
    }

    auto [Tensor_imgs, Tensor_labs, seq_lengths] = collate_fn(batch);

    std::cout << "Images size: " << Tensor_imgs.size() << std::endl;
    std::cout << "Labels size: " << Tensor_labs.size() << std::endl;
    std::cout << "Sequence Lengths: ";
    for (auto& len : seq_lengths) {
        std::cout << len << " ";
    }
    std::cout << std::endl;

    return 0;
}
*/


int main() {
//    Tensor t1(2, 3, 640, 640);
//    t1.TensorRandom(0.0, 1.0);
//
//    Tensor t2 = Tensor(t1);
//    Tensor t3 = Tensor(t1);
//    Tensor t4 = Tensor(t1);

    //Tensor t3 = t1 + t2;
    //Tensor t4 = t1 - t2;
    //Tensor t5 = t1 * t2;
    //Tensor t6 = t1 / t2;

    //Tensor t11 = t1.transpose();
    //Tensor t22 = t2.transpose2();
    //t11.print();
    //std::cout << "===================================\n"; 0.0646357
    //t22.print();

    //Tensor t5 = t1 * t2;
    //Tensor t6 = t3.matmul(t4);
    //t5.print();
    //std::cout << "===================================\n"; 45.0795
    //t6.print();

    Matrix2D m1(640, 640);
//    RandomMat(m1, 0.0, 1.0);
//    Matrix2D m2(m1);
//
//    Matrix2D m3 = m1 * m2;
//    std::cout << "===================================\n";
//    std::cout << m3;
//
//    const int iterations = 2;
//    double avx2Time = measureExecutionTime([&]() { m1 * m2; }, iterations);
//    std::cout << "AVX2 Relu function time: " << avx2Time << " seconds\n";
    return 0;
}